﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Cashier
{
    /// <summary>
    /// NumbericPad.xaml 的交互逻辑
    /// </summary>
    public partial class NumbericPad : Window
    {
        bool haveDot;
        public string numStr;

        public NumbericPad()
        {
            InitializeComponent();
            haveDot = false;
            numStr = "";
        }

        private void ClearBtn_Click(object sender, RoutedEventArgs e)
        {
            numStr = "";
            ValueLabel.Content = numStr;
            haveDot = false;
        }

        private void dotBtn_Click(object sender, RoutedEventArgs e)
        {
            if (haveDot == false)
            {
                numStr += ".";
                haveDot = true;
                ValueLabel.Content = numStr;
            }
        }

        private void BackBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!numStr.Equals(""))
            {
                if (numStr[numStr.Length - 1].Equals('.'))
                {
                    haveDot = false;
                }
                numStr = numStr.Remove(numStr.Length - 1);
                ValueLabel.Content = numStr;
            }

        }

        private void NumBtn_Click(object sender, RoutedEventArgs e)
        {
            numStr += (sender as Button).Content as string;
            ValueLabel.Content = numStr;
        }

        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            if (numStr.Equals(""))
            {
                numStr = "0.00";
            }
            this.DialogResult = true;
            this.Close();
        }
    }
}
